package com.hue.gulimail.gulimailmember.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @Author: 姚凤桥
 * @Date: 2021/11/28 19:35
 * @Description: SpringSession配置
 */
@Configuration
public class SessionConfig {
    /**
     * 配置session
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

        //设置session名字和作用范围
        cookieSerializer.setDomainName("gulimail.com");
        cookieSerializer.setCookieName("GULIMAILSESSION");

        return cookieSerializer;
    }

    /**
     * 配置SpringSession中redis的序列化方式，对象名必须为springSessionDefaultRedisSerializer
     * @return
     */
    @Bean
    public RedisSerializer springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
